/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package filmlibrary.web;

import java.io.Serializable;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author karol
 */
@ManagedBean
@SessionScoped
public class SessionBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private static final Logger logger = Logger.getLogger(LanguageSwitcher.class.getName());
    /** Creates a new instance of Session */
    String login;

    public SessionBean() {
    }

    public String logout() {
        FacesContext context = FacesContext.getCurrentInstance();
        ExternalContext ec = context.getExternalContext();

        final HttpServletRequest request = (HttpServletRequest) ec.getRequest();

        request.getSession(false).invalidate();


        return "/faces/main.xhtml?faces-redirect=true";
    }

    public String getLogin() {
        FacesContext context = FacesContext.getCurrentInstance();
        ExternalContext ec = context.getExternalContext();

        final HttpServletRequest request = (HttpServletRequest) ec.getRequest();
        login = request.getUserPrincipal().getName();
        return login;
    }
}
